package com.yaoxun.quartz.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yaoxun.core.resp.ApiResp;
import com.yaoxun.core.resp.EffectRes;
import com.yaoxun.quartz.domain.vo.AddScheduleJob;
import com.yaoxun.quartz.domain.vo.DelScheduleJob;
import com.yaoxun.quartz.domain.vo.UpdateScheduleJob;
import com.yaoxun.quartz.service.ScheduleJobService;

@RestController
@RequestMapping("/quartz")
public class ScheduleJobController {

	@Autowired
	private ScheduleJobService scheduleJobService;
	
	/**
	 * 新增定时任务
	 * @param addScheduleJob
	 * @return
	 */
	@PostMapping("/add")
	public ApiResp<EffectRes> add(@RequestBody AddScheduleJob addScheduleJob) {
		scheduleJobService.add(addScheduleJob);
		return ApiResp.of(null);
	}
	
	/**
	 * 更新定时任务
	 * @param updateScheduleJob
	 * @return
	 */
	@PostMapping("/update")
	public ApiResp<EffectRes> update(@RequestBody UpdateScheduleJob updateScheduleJob) {
		scheduleJobService.update(updateScheduleJob);
		return ApiResp.of(null);
	}
	
	/**
	 * 删除定时任务
	 * @param delScheduleJob
	 * @return
	 */
	@PostMapping("/delete")
	public ApiResp<EffectRes> delete(@RequestBody DelScheduleJob delScheduleJob) {
		scheduleJobService.delete(delScheduleJob);
		return ApiResp.of(null);
	}
	
}
